home *** CD-ROM | disk | FTP | other *** search
- /*
- File: USBEnetStub.c
-
- Contains: xxx put contents here xxx
-
- Version: xxx put version here xxx
-
- Copyright: © 1998-2000 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: xxx put dri here xxx
-
- Other Contact: xxx put other contact here xxx
-
- Technology: xxx put technology here xxx
-
- */
-
- #include <Errors.h>
- #include <CodeFragments.h>
-
- #include "USBEnet.h"
- #include "USBEnetStub.h"
- #include "USBEnetDriver.h"
- #include "ShimEnetStub.h"
- #include "ShimEnetHAL.h"
- #include "USBEnetVersion.h"
-
- //------------------------------------------------------
- //
- // Globals
- //
- //------------------------------------------------------
-
- ShimEnetGlobals* gGlobals;
-
- //------------------------------------------------------
- //
- // This is the driver description structure that the expert looks for first.
- // If it's here, the information within is used to match the driver
- // to the device whose descriptor was passed to the expert.
- // Information in this block is also used by the expert when an
- // entry is created in the Name Registry.
- //
- //------------------------------------------------------
-
- USBDriverDescription TheUSBDriverDescription =
- {
- // Signature info
- kTheUSBDriverDescriptionSignature,
- kInitialUSBDriverDescriptor,
-
- // Device Info
- kUSBVendorID, // vendor ID
- kUSBProductID, // product ID
- 0, // version of product = not device specific
- 0, // protocol = not device specific
-
- // Interface Info
- 0, // Configuration Value (doesn't matter)
- 0, // Interface Number
- kUSBCommClass, // Interface Class
- 6, // Interface SubClass (Ethernet Control Model)
- 0, // Interface Protocol (none)
-
- // Driver Info
- kUSBRegName, // Driver name for Name Registry
- kUSBCommClass, // Device Class
- 0, // Device Subclass
- kVMajor, // version of driver (see USBEnetVersion.h)
- kVMinor,
- kVStage,
- kVRelease,
-
- // Driver Loading Info
- // kUSBDoNotMatchGenericDevice // Flags
- 0
- };
-
- USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
- {
- kClassDriverPluginVersion, // Version of this structure
- USBEnetDriverValidateHW, // Hardware Validation Procedure
- USBEnetDriverInitialize, // Initialization Procedure
- USBEnetDriverInitInterface, // Interface Initialization Procedure
- USBEnetDriverFinalize, // Finalization Procedure
- USBEnetDriverNotifyProc,
- };
-
- /***********************************************************************************/
- // Function: BuildName(USBRef)
- // Description: This routine uses the name registry LocationID to construct
- // the devices real name
- //
- // Input: USBRef - USB Device Ref, reftype - true (Device), False (interface)
- // Output:
- /***********************************************************************************/
- static void BuildName(USBDeviceRef USBRef, Boolean reftype)
- {
- OSStatus err = noErr;
- RegEntryIter cookie;
- RegEntryID theID;
- Boolean done;
- UInt32 Rlocation;
- UInt8 *location = (unsigned char *)&Rlocation;
- RegPropertyValueSize theSize;
- UInt16 offs, i;
- UInt8 asctmp = 0;
-
- TraceMessage(0, kDrvName"- Entering BuildName");
-
- err = RegistryEntryIDInit(&theID);
- if (err != noErr)
- {
- StatusMessage(USBRef, kDrvName"- BuildName: RegistryEntryIDInit failed - ", err);
- return;
- }
-
- err = RegistryEntryIterateCreate(&cookie);
- if (err != noErr)
- {
- StatusMessage(USBRef, kDrvName"- BuildName: RegistryEntryIterateCreate failed - ", err);
- return;
- }
-
- if (reftype)
- {
- StatusMessage(USBRef, kDrvName"- BuildName: Using Device Ref - ", USBRef);
- err = RegistryEntrySearch(&cookie, kRegIterDescendants, &theID, &done, "deviceRef", (const void *)&USBRef, (RegPropertyValueSize) sizeof(USBRef));
- } else {
- StatusMessage(USBRef, kDrvName"- BuildName: Using Interface Ref - ", USBRef);
- err = RegistryEntrySearch(&cookie, kRegIterDescendants, &theID, &done, "interfaceRef", (const void *)&USBRef, (RegPropertyValueSize) sizeof(USBRef));
- }
-
- if (err != noErr)
- {
- StatusMessage(USBRef, kDrvName"- BuildName: RegistryEntrySearch failed - ", err);
- RegistryEntryIterateDispose(&cookie);
- return;
- }
-
- theSize = sizeof(Rlocation);
- err = RegistryPropertyGet(&theID, "locationID", &Rlocation, &theSize);
- if (err != noErr)
- {
- StatusMessage(USBRef, kDrvName"- BuildName: RegistryPropertyGet failed - ", err);
- RegistryEntryIterateDispose(&cookie);
- return;
- }
-
- gGlobals->theID = theID; // save our reg entry
- offs = (gGlobals->rname[0] + 1);
- for (i=1; i<=theSize; i++)
- {
- asctmp = (location[i-1] >> 4);
- if (asctmp != 0)
- gGlobals->rname[offs++] = Asciify(location[i-1] >> 4);
-
- asctmp = (location[i-1] & 0x0F);
- if (asctmp != 0)
- gGlobals->rname[offs++] = Asciify(location[i-1]);
-
- asctmp = 0;
- }
- gGlobals->rname[0] = offs;
-
- RegistryEntryIterateDispose(&cookie);
- }
-
- /***********************************************************************************/
- // Function: USBEnetDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
- // Description: Called upon load by Expert
- //
- // Input: Device reference, Device descriptor
- // Output: noErr
- /***********************************************************************************/
-
- static OSStatus USBEnetDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
- {
- #pragma unused (device, desc)
-
- TraceMessage(0,kDrvName"- Entering USBEnetDriverValidateHW");
-
- return noErr;
- }
-
- /***********************************************************************************/
- // Function: OSStatus USBEnetDriverInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc,
- // UInt32 busPowerAvailable)
- // Description: Called upon load by Expert
- //
- // Input: Device reference, Device descriptor, bus power available
- // Output: result
- /***********************************************************************************/
-
- static OSStatus USBEnetDriverInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
- {
- #pragma unused (busPowerAvailable)
-
- OSStatus err;
-
- TraceMessage(0,kDrvName"- Entering USBEnetDriverInitialize");
-
- gGlobals = (ShimEnetGlobals*)PoolAllocateResident(sizeof(ShimEnetGlobals),true);
- if (gGlobals == NULL)
- goto bail;
-
- USBExpertStatus(0, kDrvName"- USBEnetDriverInitialize: Loading as Class - "kVers2Long Bugon, 0);
-
- // Could use the Product string but for now we don't
- BlockMoveData(kDrvName, &gGlobals->rname, sizeof(kDrvName));
- BuildName(device, true);
- err = USBEnetDriverEntry(device, pDesc);
-
- if (err != noErr)
- {
- StatusMessage(0, kDrvName"- USBEnetDriverInitialize: Configuration failed", err);
- goto bail;
- }
- return noErr;
-
- bail:
- if (gGlobals)
- PoolDeallocate(gGlobals);
- gGlobals = NULL;
-
- return openErr;
- }
-
- /***********************************************************************************/
- // Function: USBEnetDriverInitInterface(UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc,
- // USBDeviceDescriptor *deviceDesc, USBDeviceRef device)
- // Description: Called to initialize driver for an individual interface -
- // either by expert or internally by driver
- //
- // Input: Interface number, Interface descriptor, Device Descriptor, Device Reference
- // Output: result
- /***********************************************************************************/
-
- static OSStatus USBEnetDriverInitInterface(UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, USBDeviceDescriptor *deviceDesc, USBDeviceRef device)
- {
- #pragma unused (interfaceNum, interfaceDesc)
-
- OSStatus err;
-
- TraceMessage(0,kDrvName"- Entering USBEnetDriverInitInterface");
-
- if (gGlobals == NULL)
- gGlobals = (ShimEnetGlobals*)PoolAllocateResident(sizeof(ShimEnetGlobals),true);
-
- if (gGlobals == NULL)
- goto bail;
-
- USBExpertStatus(0, kDrvName"- USBEnetDriverInitInterface: Loading as Interface "kVers2Long Bugon, 0);
-
- // Could use the Product string but for now we don't
- BlockMoveData(kDrvName, &gGlobals->rname, sizeof(kDrvName));
- BuildName(device, false);
- err = USBEnetDriverEntry(device, deviceDesc);
-
- if (err != noErr)
- {
- StatusMessage(0, kDrvName"- USBEnetDriverInitInterface: Configuration failed", err);
- goto bail;
- }
-
- return noErr;
-
- bail:
- if (gGlobals)
- PoolDeallocate(gGlobals);
- gGlobals = NULL;
-
- return openErr;
- }
-
- /***********************************************************************************/
- // Function: USBEnetDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc)
- // Description: Called by Expert when driver is being shut down
- //
- // Input: Device reference, Device descriptor
- // Output: noErr
- /***********************************************************************************/
-
- static OSStatus USBEnetDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc)
- {
- #pragma unused (device, pDesc)
-
- TraceMessage(0,kDrvName"- Entering USBEnetDriverFinalize");
-
- if (gGlobals)
- {
- /* Now we can kill all the IO */
- KillUSBIO();
- RemoveShimDrvr(true); // force close - let the shim handle it
- PoolDeallocate(gGlobals);
- gGlobals = NULL;
- }
-
- return noErr;
- }
-
- /***********************************************************************************/
- // Function: ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify)
- // Description:
- //
- // Input: Notification proc pointer
- // Output: noErr
- /***********************************************************************************/
-
- static OSStatus ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify)
- {
- #pragma unused (pExpertNotify)
-
- TraceMessage(0,kDrvName"- Entering ExpertEntryProc");
-
- return noErr;
- }
-
- /***********************************************************************************/
- // Function: USBEnetDriverNotifyProc(UInt32 notification, void *pointer)
- // Description:
- //
- // Input: Notification and pointer
- // Output: result
- /***********************************************************************************/
-
- static OSStatus USBEnetDriverNotifyProc(UInt32 notification, void *pointer, UInt32 refcon)
- {
- #pragma unused (pointer, refcon)
-
- OSErr err = noErr;
-
- TraceMessage(0,kDrvName"- Entering USBEnetDriverNotifyProc");
- StatusMessage(0, kDrvName"- USBEnetDriverNotifyProc: Notification = ", notification);
-
- if (notification == kNotifySystemSleepRequest)
- {
- if (gGlobals)
- {
- if (gGlobals->openSession) // Look to see if we're selected
- {
- err = -1; // Defer for now - it's only a request
- }
- }
- }
-
- return err;
- }